package Robot;
import javaclient3.*;

/**
 * Base class for Sensor and Actuator
 * @author Alejandro Pustowka
 */
public abstract class Device {

    public final static int DEBUG_HIGH = 0;
    public final static int DEBUG_LOW = 1;
    public final static int DEBUG_DISABLED = 2;

    /**
     * The PlayerDevice
     */
    private PlayerDevice playerDevice;
    /**
     * Name of the device. Useful when having arrays of devices.
     */
    private String name;
    /**
     * The Player client.
     */
    protected Robot robot;
    /**
     * Id del dispositivo
     */
    protected int deviceIndex;

    /**
     * Defines how much debugging is neeeded
     */
    protected int debugMode = DEBUG_DISABLED;

    /**
     * Constructor for device.
     * @param robot The connection to the Player server.
     * @param name The name of the device. Useful when having arrays of devices.
     * @param index The index of the interface in the robot (see Player doc).
     */
    public Device(Robot robot, String name, int index) {
        this.robot=robot;
        
        this.name=name;
        this.deviceIndex=index;//robot.getId();
        
    }
    
    
    /**
     * The Player Device associated with this device.
     * @return PlayerDevice
     */
    public PlayerDevice getPlayerDevice() {
        return playerDevice;
    }

    /**
     * Sets the Player Device associated with this device.
     * @param val  The associated PlayerDevice
     */
    public void setPlayerDevice(PlayerDevice val) {
        this.playerDevice = val;
    }

    /**
     * The name of the device
     * @return name of the device.
     */
    public String getName() {
        return name;
    }

    /**
     * Sets the name of the device
     * @param name The name of the device.
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * The robot associated to this device
     * @return associated Robot
     */
    public Robot getRobot(){
        return robot;
    }

    /**
     * The id of the robot associated with this device
     * @return Id of the Robot
     */
    public int getRobotId(){
        return robot.getIndex();
    }

    /**
     * Defines if data is ready to be readed from this device.
     * @return true if device data is ready, false otherwise.
     */
    public abstract boolean isReady();

    /**
     * Sets the debug mode. Use the constants defined in this class.
     * @param debugMode <ul><li></ul>
     */
    public void setDebugMode(int debugMode)
    {
        this.debugMode = debugMode;
    }
}
